class Exploitdb < Formula
  desc "Database of public exploits and corresponding vulnerable software"
  homepage "https://www.exploit-db.com/"
  url "https://github.com/offensive-security/exploitdb.git",
      tag:      "2021-11-18",
      revision: "a4598bc3c4c3fd2047421df519b5266daafbc6e0"
  version "2021-11-18"
  license "GPL-2.0-or-later"
  head "https://github.com/offensive-security/exploitdb.git", branch: "master"

  bottle do
    sha256 cellar: :any_skip_relocation, arm64_monterey: "141e282a58c59bc61f014c25fb019fa5ed6521d02e987f860481eb3a7913c074"
    sha256 cellar: :any_skip_relocation, arm64_big_sur:  "e04b22b365438c31f985504525ce6725cc802f984546f0eb8e9dfdc22daadc8e"
    sha256 cellar: :any_skip_relocation, monterey:       "2fbb6057340b9d6d643538949727148dacd88469c84e45451542e8ba9a274fa4"
    sha256 cellar: :any_skip_relocation, big_sur:        "f4daed19699103a5c21275131c4e72654b1dea9af27b1cf0a6c9f287f38f2dc8"
    sha256 cellar: :any_skip_relocation, catalina:       "86d6f2c81940057f9cc993e8822c3a88a4fd195d88f434079b407e04aa53477a"
    sha256 cellar: :any_skip_relocation, x86_64_linux:   "5e404c7e7b50e021a21917c202df60f6b7bae087ab3261231a28f62786c5b2bb"
  end

  def install
    inreplace "searchsploit",
              "rc_file=\"\"", "rc_file=\"#{etc}/searchsploit_rc\""

    optpath = opt_share/"exploitdb"
    inreplace ".searchsploit_rc" do |s|
      s.gsub! "\"/opt/exploitdb\"", optpath
      s.gsub! "\"/opt/exploitdb-papers\"", "#{optpath}-papers"
    end

    bin.install "searchsploit"
    etc.install ".searchsploit_rc" => "searchsploit_rc"

    pkgshare.install %w[.git exploits files_exploits.csv files_shellcodes.csv
                        shellcodes]
  end

  test do
    system "#{bin}/searchsploit", "sendpage"
  end
end
